total = document.documentElement.clientHeight;
colHeight = total-document.getElementById("main-content").offsetTop;
document.getElementById("main-content").style.height=colHeight+"px";
$(window).resize(function(){
	total = document.documentElement.clientHeight;
	colHeight = total-document.getElementById("main-content").offsetTop;
	document.getElementById("main-content").style.height=colHeight+"px";
});
/*通用*/
function fixWidth(percent)  
{  
    return document.body.clientWidth * percent ; 
}
$('.navScrollbar').height($('#main-content').height()-60);
$('.menu-min.navScrollbar').height($('#main-content').height()-0);
$(window).resize(function(){
	$('.navScrollbar').height($('#main-content').height()-60);
	$('.menu-min.navScrollbar').height($('#main-content').height()-0);
});
$(".navScrollbar").mCustomScrollbar({
    mouseWheel:{ enable: true }
});
$('.padding0').height($('#main-content').height()-70);
$('.padding20').height($('#main-content').height()-110);
$(window).resize(function(){
	$('.padding0').height($('#main-content').height()-70);
	$('.padding20').height($('#main-content').height()-110);
});
/*var mode =1;
$(function(){
	$('#sidebar').mousemove(function(e){
		$(this).removeClass('menu-min');	
		try{
			$(window).trigger('resize');
		}catch(e){
		}
		mode = 2;
		e.stopPropagation();
	});
});
$(function(){
	$(document).mousemove(function(i){
		$('#sidebar').addClass('menu-min');
		if(mode ==2){
			mode = 1;
			setTimeout(function(){
				$(window).trigger('resize');
			},1);
		}
		i.stopPropagation();
	});
});*/
//ajax 选项卡
$('#ajaxtab .tabbtn li a').click(function(){
	var thiscity = $(this).attr("href");
	$("#ajaxtab .loading").ajaxStart(function(){
		$(this).show();
	}); 
	$("#ajaxtab .loading").ajaxStop(function(){
		$(this).hide();
	}); 
	$('#ajaxtab .tabcon').load(thiscity);
	$('#ajaxtab .tabbtn li a').parents().removeClass("current");
	$(this).parents().addClass("current");
	return false;
});
$('#ajaxtab .tabbtn li a').eq(0).trigger("click");


/*设置*/
$(function(){
	$('#setUp').click(function(e){
		$('.setUp').show();
		e.stopPropagation();
	});
	$('.setUp').click(function(e){
		e.stopPropagation();
	});
	$(document).click(function(){
		$('.setUp').hide();
	});
	$('.setUp a').click(function(){
		$('.setUp').hide();
	});
});  
/*菜单高亮*/
  function getShowHref(){
  	var href=$('meta[name=others]').attr('content');
  	return href || location.href;
  }
  var urlstr = getShowHref();
  var urlstatus=false;
  $("#nav .submenu li").each(function () {
	 var parent=$(this).closest('ul').closest('li'),hrefs=[],currentHref;
	 currentHref=$(this).find('a').attr('href');
	 $(this).closest('ul').find('a').each(function(){
		 hrefs.push($(this).attr('href'));
	 });
	 var flag=false;
	 $.each(hrefs,function(i,v){
		  if ((urlstr + '/').indexOf(v) > -1&&v!='') {
		  	flag=true
		  }
	});
	if(flag){
		 parent.addClass('active');
	}else{
		 parent.removeClass('active');
	}
    if ((urlstr + '/').indexOf(currentHref) > -1&&currentHref!='') {
      $(this).addClass('active'); urlstatus = true;
    } else {
      $(this).removeClass('active');
    }
  });
  $('#nav li>a').each(function(){
	var href=$(this).attr('href');
	if ((urlstr + '/').indexOf(href) > -1&&href!='') {
		$(this).closest('li').addClass('active');
		urlstatus=true;
	}
	});;
  if (!urlstatus) {
	  var first=$("#nav .submenu li").eq(0);
	  first.addClass('active'); 
  	  var parent=first.closest('ul').closest('li');
	  parent.addClass('active');
  }

//构建表单  不显示参数
$.extend({
    StandardPost:function(url,args){
        var body = $(document.body),
            form = $("<form method='post'  target='_blank'></form>"),
            input;
        form.attr({"action":url});
        $.each(args,function(key,value){
            input = $("<input type='hidden'>");
            input.attr({"name":key});
            input.val(value);
            form.append(input);
        });

        form.appendTo(document.body);
        form.submit();
        document.body.removeChild(form[0]);
    }
});

/*tab*/  
(function($){
	
	$.fn.rTabs = function(options){
		
		//默认值
		var defaultVal = {
			btnClass:'.j-tab-nav',	/*按钮的父级Class*/
			conClass:'.j-tab-con',	/*内容的父级Class*/
			bind:'hover',	/*事件参数 click,hover*/
			animation:'0',	/*动画方向 left,up,fadein,0 为无动画*/
			speed:300, 	/*动画运动速度*/
			delay:200,	/*Tab延迟速度*/
			auto:false,	/*是否开启自动运行 true,false*/
			autoSpeed:3000	/*自动运行速度*/
		};
		
		//全局变量
		var obj = $.extend(defaultVal, options),
			evt = obj.bind,
			btn = $(this).find(obj.btnClass),
			con = $(this).find(obj.conClass),
			anim = obj.animation,
			conWidth = con.width(),
			conHeight = con.height(),
			len = con.children().length,
			sw = len * conWidth,
			sh = len * conHeight,
			i = 0,
			len,t,timer;

		return this.each(function(){
			
			//判断动画方向
			function judgeAnim(){
				var w = i * conWidth,
					h = i * conHeight;
				btn.children().removeClass('current').eq(i).addClass('current');
				switch(anim){
					case '0':
					con.children().hide().eq(i).show();
					break;
					case 'left':
					con.css({position:'absolute',width:sw}).children().css({float:'left',display:'block'}).end().stop().animate({left:-w},obj.speed);
					break;
					case 'up':
					con.css({position:'absolute',height:sh}).children().css({display:'block'}).end().stop().animate({top:-h},obj.speed);
					break;
					case 'fadein':
					con.children().hide().eq(i).fadeIn();
					break;
				}
				$(window).trigger('resize');
			}
			
			//判断事件类型
			if(evt == "hover"){
				btn.children().hover(function(){
					var j = $(this).index();
					function s(){
						i = j;
						judgeAnim();
					}
					timer=setTimeout(s,obj.delay);
				}, function(){
					clearTimeout(timer);
				})
			}else{
				btn.children().bind(evt,function(){
					i = $(this).index();
					judgeAnim();
				})
			}
			
			//自动运行
			function startRun(){
				t = setInterval(function(){
					i++;
					if(i>=len){
						switch(anim){
							case 'left':
							con.stop().css({left:conWidth});
							break;
							case 'up':
							con.stop().css({top:conHeight});
						}	
						i=0;
					}
					judgeAnim();
				},obj.autoSpeed)
			}
			
			//如果自动运行开启，调用自动运行函数
			if(obj.auto){
				$(this).hover(function(){
					clearInterval(t);
				},function(){
					startRun();
				})
				startRun();
			}
			
		})
		
	}
	
})(jQuery);












